<?php
require_once dirname(__FILE__).'/common.inc.php';
use IFeng\Process\Process;
/*
 * function mark() is defined in common.inc.php.
 * It echos a line with PID and time.
 * e.g. mark('MAIN START');//echo MAIN START	pid:6819	time:47:53
 */  
mark('MAIN START');

class Sample implements IFeng\Process\Runnable {
	/**
	 * @see IFeng\Process\Runnable::run()
	 */
	public function run() {
		mark('---CHILD START');
		sleep(3);
		mark('---CHILD END');
	}
}

for ($i = 0; $i < 3; $i++) {
	//fork() returns immediately.
	$childProcess = Process::current()->fork(new Sample());
	echo "FORK $i, Child PID is ".$childProcess->getPid()."\n";
}

sleep(4);
mark('MAIN END');